<?php

require_once 'WSL/Dispatcher/Node.php';
require_once 'PHPUnit/Framework/TestCase.php';

class WSL_Dispatcher_Node_Test extends PHPUnit_Framework_TestCase
{
	/**
	 * @var WSL_Dispatcher_Node
	 */
	private $_node;
	
    public function setUp()
    {
    	$this->_node = new WSL_Dispatcher_Node('example',
    	                                       'Controller.Example',
    	                                       'default');
    }
    
    public function tearDown()
    {
        unset($this->_node);
    }
    
    public function reset()
    {
    	$this->setUp();
    	$this->tearDown();
    }
    
    public function testGetController()
    {
    	$this->assertEquals('Controller.Example', $this->_node->getController());
    }
    
    public function testGetAction()
    {
    	$this->assertEquals('default', $this->_node->getAction());
    }
    
    public function testGetLiteral()
    {
    	$this->assertEquals('example', $this->_node->getLiteral());
    }
    
    public function testIsActive()
    {
    	$this->assertFalse($this->_node->isActive());
    	
    	$this->_node->setActive(true);
    	
    	$this->assertTrue($this->_node->isActive());
    }
    
    public function testGetNumChildren()
    {
    	$this->assertEquals(0, $this->_node->getNumChildren());
    	
    	$node = new WSL_Dispatcher_Node('test');
    	
    	$this->_node->addChild($node);
    	
    	$this->assertEquals(1, $this->_node->getNumChildren());
    	
    	$this->tearDown();
    	$this->setUp();
    }
    
    public function testContains()
    {
    	$this->assertFalse($this->_node->contains('test'));
    	
    	$node = new WSL_Dispatcher_Node('test');
    	
    	$this->_node->addChild($node);
    	
    	$this->assertTrue($this->_node->contains('test'));
    	
    	$this->tearDown();
    	$this->setUp();
    }
    
    public function testGetChildByLiteral()
    {
    	$this->assertEquals(null, $this->_node->getChildByLiteral('test'));
    	
    	$node = new WSL_Dispatcher_Node('test');
    	
    	$this->_node->addChild($node);
    	
    	$this->assertEquals($node, $this->_node->getChildByLiteral('test'));
    	
    	$this->tearDown();
    	$this->setUp();
    }
    
    public function testSetAction()
    {
    	$this->_node->setAction('test2');
    	
    	$this->assertEquals('test2', $this->_node->getAction());
    	
    	$this->tearDown();
    	$this->setUp();
    }
    
    public function testSetController()
    {
    	$this->_node->setController('Controller.Test2');
    	
    	$this->assertEquals('Controller.Test2', $this->_node->getController());
    	
    	$this->tearDown();
    	$this->setUp();
    }
    
    public function testSetLiteral()
    {
    	$this->_node->setLiteral('test2');
    	
    	$this->assertEquals('test2', $this->_node->getLiteral());
    	
    	$this->tearDown();
    	$this->setUp();
    }
    
    public function testGetMetaValues()
    {
    	$metaValues = $this->_node->getMetaValues();
    	
    	$this->assertEquals(true, empty($metaValues));
    	
    	$this->_node->addMetaValue('key', 'value');
    	
    	$this->assertEquals('value', $this->_node->getMetaValue('key'));
    	
    	$this->reset();
    }
    
    public function testGetVarNames()
    {
    	$varNames = $this->_node->getVarNames();
    	
    	$this->assertEquals(true, empty($varNames));
    	
    	$this->_node->addVarName('varName', 0);
    	
    	$varNames = $this->_node->getVarNames();
    	
    	$this->assertEquals(false, empty($varNames));
    	
    	$this->reset();
    }
    
    public function testGetExpReg()
    {
    	
    }
}
?>